package com.wyl.niupi.framework.util.swagger;


import com.wyl.niupi.framework.vo.ResponseVo;
import com.wyl.niupi.frameworkExt.controller.BaseControllerExt;
import com.wyl.niupi.yxc.entity.YxcGoods;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 吴宇亮 on 2020/11/23 17:25
 */
@Tag(name = "SwaggerDemo", description = "swagger注解演示demo")
@RestController
@RequestMapping("/demo/swaggerDemo")
public class SwaggerDemo extends BaseControllerExt {

    @Operation(tags = {"SwaggerDemo"}, summary = "基本类型入参demo", description = "详细描述...", parameters = {
        @Parameter(name = "id", description = "主键", example = "1"),
        @Parameter(name = "name", description = "姓名", example = "张三", required = false),
        @Parameter(name = "money", description = "钱", example = "100万", required = false),
    })
    @GetMapping("/_01_testInputSimple")
    public ResponseVo _01_testInputSimple(){
        return sendSuccess();
    }

    @Operation(tags = {"SwaggerDemo"},summary = "枚举类型入参demo", description = "详细描述...", parameters = {
        @Parameter(name = "type", description = "性别", schema = @Schema(type = "string", defaultValue = "男", allowableValues = { "男", "女", "未知" }))
    })
    @GetMapping("/_02_testInputEnum")
    public ResponseVo _02_testInputEnum(){
        return sendSuccess();
    }

    @Operation(tags = {"SwaggerDemo"},summary = "设置参数输入来源demo", description = "比如说QUERY、还是form、还是restful的Path",
        parameters = {
            @Parameter(name = "param1", description = "参数1", in = ParameterIn.QUERY),
            @Parameter(name = "param2", description = "参数2", in = ParameterIn.PATH),
            @Parameter(name = "param3", description = "参数3", in = ParameterIn.HEADER),
            @Parameter(name = "param4", description = "参数4", in = ParameterIn.COOKIE),
            @Parameter(name = "param5", description = "参数5", in = ParameterIn.DEFAULT),
        }
    )
    @GetMapping("/_03_testInputType")
    public ResponseVo _03_testInputType(){
        return sendSuccess();
    }

    @Operation(tags = {"SwaggerDemo"},summary = "bean入参demo", description = "详细描述...")
    @GetMapping("/_04_testInputBean")
    public ResponseVo _04_testInputBean(@Parameter(name = "peopleBean", description = "人") SwaggerPeopleBean peopleBean){
        return sendSuccess();
    }

    @Operation(tags = {"SwaggerDemo"},summary = "Map入参demo（暂不支持）", description = ApiConst.mapDesc)
    @GetMapping("/_05_testInputMap")
    public ResponseVo<SwaggerPeopleBean> _05_testInputMap(
            @Parameter(name = "yxcGoods", description = "商品") Map<String, List<YxcGoods>> map){
        return sendSuccess();
    }

    @Operation(tags = {"SwaggerDemo"}, summary = "响应demo",
        responses = {
            @ApiResponse(responseCode = "200", description = "{\"code\": 400, \"data\": {\"name\": \"xxx\", \"age\": 10}}")
        }
    )
    @GetMapping(path = "/_06_testOutputJson")
    public ResponseVo _06_testOutputJson() {
        return sendSuccess();
    }
}
